import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
// import { rules } from '/@/utils/helper/validator';
// import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '序号',
    align: 'center',
    width: 150,
    dataIndex: 'sysOrgCode',
  },
  // {
  //   title: 'CREATE_DATE',
  //   align: 'center',
  //   width: 150,
  //   dataIndex: 'createDate',
  // },
  // {
  //   title: 'AES_TEXT',
  //   align: 'center',
  //   dataIndex: 'aesText',
  //   // customRender({ text }) {
  //   //   return text;
  //   // },
  // },
  {
    title: 'UUID',
    align: 'center',
    width: 280,
    dataIndex: 'uuid',
  },
  {
    title: 'AES_TEXT',
    align: 'left',
    dataIndex: 'aesText',
    customRender({ text }) {
      return text
        ?.replaceAll(' ', '')
        .match(/.{1,2}/g)
        .reduce((pre, item) => {
          return pre + String.fromCharCode(parseInt(item, 16));
        }, '');
    },
  },
  {
    title: 'index',
    align: 'center',
    width: 150,
    dataIndex: 'sysOrgCode',
    customRender({ text }) {
      return 1501 - parseInt(text);
    },
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: 'UUID',
    field: 'uuid',
    component: 'Input',
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: 'UUID',
    field: 'uuid',
    component: 'Input',
    dynamicRules: () => {
      return [
        {
          required: true,
          validator(_, value, callback) {
            if (value.length == 0) {
              callback('请输入UUID');
            }
            if (!/^[0-9A-Fa-f]+$/.test(value)) {
              callback('UUID是十六进制字符串');
            } else {
              callback();
            }
          },
          // message: '请输入UUID!',
        },
      ];
    },
    componentProps: {
      maxlength: 16,
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
